home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 8 / 008.d81 / pps #17 < prev    next >
Text File  |  2022-08-26  |  4KB  |  209 lines

  1.  
  2.  PEEKs, POKEs, and SYSes -- part 17
  3.  
  4.           by Jimmy Weiler
  5.  
  6. ======================================
  7.  
  8. Location: 53248      Hexadecimal:$D000
  9. Official Label: VIC           Type:RAM
  10. Useful BASIC commands:      PEEK, POKE
  11.  
  12. --------------------------------------
  13.  
  14.  
  15. VIC is the acronym for the Commodore's
  16.  
  17. Video Interface Controller Chip.
  18.  
  19. The range of memory we are interested
  20.  
  21. in is 53248 to 53294 ($D000 to $D02E).
  22.  
  23. These locations control (among other
  24.  
  25. things) sprites and the video screen.
  26.  
  27.  
  28. It is customary to set the variable
  29.  
  30. 'V' to 53248 in a program and refer to
  31.  
  32. these addresses as V plus an offset,
  33.  
  34. so that's how we'll talk about them in
  35.  
  36. this article, too.
  37.  
  38. (... like this...  LET V = 53248)
  39. (                  POKE V + 21,0)
  40.  
  41.  
  42.   We'll start by talking about
  43.  
  44. sprites.  'Sprite' is short for
  45.  
  46. 'Movable Object Block' (don't ask).
  47.  
  48. They're called MOB's because each
  49.  
  50. sprite is a small piece of memory (a
  51.  
  52. block) that represents an image of
  53.  
  54. some object.  That image can be moved
  55.  
  56. to any location on the screen.
  57.  
  58.  
  59.   The VIC chip takes care of the hard
  60.  
  61. part -- putting the image on the
  62.  
  63. screen.  All you have to do is design
  64.  
  65. the image and tell VIC which sprite it
  66.  
  67. is, where to find the image, where to
  68.  
  69. put the image, what color the image
  70.  
  71. is, what size to make the image, and
  72.  
  73. whether to put it in front of or
  74.  
  75. behind the text.  Simple, right?
  76.  
  77. That's why we're covering it in this
  78.  
  79. series.
  80.  
  81.  
  82.  
  83.   Let's deal with each of these items
  84.  
  85. singly.  First, 'design the image'.
  86.  
  87.  
  88.   Sprite design is at best a tedious
  89.  
  90. process.  At worst, it is pure
  91.  
  92. drudgery.  If you have Commodore's
  93.  
  94. Disk Bonus Pack, use the SPRITE EDITOR
  95.  
  96. program on it.  If you don't have it,
  97.  
  98. pay close attention.
  99.  
  100.  
  101.   I hope you understand binary, bits,
  102.  
  103. and bytes.  Otherwise none of this
  104.  
  105. will make much sense.
  106.  
  107.  
  108.   A sprite image is defined by a piece
  109.  
  110. of memory 63 bytes long.  The image is
  111.  
  112. 3 bytes wide and 21 bytes tall.  Each
  113.  
  114. bit in the image represents a single
  115.  
  116. pixel in the unexpanded sprite.  When
  117.  
  118. the image appears on the screen the
  119.  
  120. bytes are laid out like this:
  121.  
  122.  
  123.       --------------------------
  124.      ! byte01 ! byte02 ! byte03 !
  125.      ! byte04 ! byte05 ! byte06 !
  126.                   .
  127.                  etc.
  128.                   .
  129.      ! byte55 ! byte56 ! byte57 !
  130.      ! byte58 ! byte59 ! byte60 !
  131.      ! byte61 ! byte62 ! byte63 !
  132.       --------------------------
  133.  
  134. The bits are arranged like this:
  135.  
  136.       --------------------------
  137.      ! byte01 ! byte02 ! byte03 !
  138.      !76543210!76543210!76543210!
  139.  
  140.  
  141.   Ok, got all that?  Now let's make a
  142. sprite that looks like an umbrella.
  143.  
  144.  
  145.      76543210 76543210 76543210
  146.      -------- -------- --------
  147.  1  !       *!********!*       !  3
  148.  4  !    ****!********!****    !  6
  149.  7  ! *******!********!******* !  9
  150. 10  !********!********!********! 12
  151. 13  !        !   **   !        ! 15
  152. 16  !        !   **   !        ! 18
  153. 19  !        !   **   !        ! 21
  154. 22  !        !   **   !        ! 24
  155. 25  !        !   **   !        ! 27
  156. 28  !        !   **   !        ! 30
  157. 31  !        !   **   !        ! 33
  158. 34  !        !   **   !        ! 36
  159. 37  !        !   **  *!*       ! 39
  160. 40  !        !    ****!        ! 42
  161. 43  !        !        !        ! 45
  162. 46  !        !        !        ! 48
  163.    ...the rest of the bytes (49 to 63)
  164.       are blanks (zeros).
  165.  
  166.  
  167. Now, jot down the value of each of the
  168.  
  169. bytes in that chart: (Let's put them
  170.  
  171. in data statements so we can keep
  172.  
  173. better track of them.)
  174.  
  175.  
  176. 50 DATA 1,255,128,15,255,240,127,255,
  177. 254,255,255,255,0,24,0,0,24,0,0,24,0
  178.  
  179. 60 DATA 0,24,0,0,24,0,0,24,0,0,24,0
  180. 0,24,0,0,25,128,0,15,0,0,0,0,0,0,0,0,
  181.  
  182. 70 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,0
  183.  
  184.  
  185.   OK, now let's put that data into
  186.  
  187. a block of memory (remember, we're
  188.  
  189. dealing with movable object BLOCKs
  190.  
  191. here).
  192.  
  193.  
  194. 80 FOR BL = 832 to 832 + 62
  195. 90 READ D
  196. 100 POKE BL,D
  197. 110 NEZT BL
  198.  
  199.  
  200.   There!! The data has been POKEd into
  201.  
  202. part of the cassette input buffer and
  203.  
  204. we're done designing the sprite's
  205.  
  206. shape.
  207.  
  208. -------- Continued in Part 18 --------
  209.